package com.design.strategy.demo;

/**
 * Created by yijy on 2018/1/16.
 */
public class ComparableCatHeight implements Comparable<Cat> {

    @Override
    public void compare(Cat[] a) {
        sort(a);
    }

    public void sort(Cat[] arr){
        for (int i=0;i<arr.length;i++){
            for(int j=i;j<arr.length;j++){
                swap(arr,i,j);
            }
        }
    }

    public static Cat[] swap(Cat[] arr,int i,int j){
        Cat cat = null;
        if(arr[i].getHeight()>arr[j].getHeight()){
            cat = arr[i];
            arr[i] = arr[j];
            arr[j] = cat;
        }
        if(arr[i].getWeight()>arr[j].getWeight()){
            cat = arr[i];
            arr[i] = arr[j];
            arr[j] = cat;
        }
        return arr;
    }
}
